package fy.mdm.operator;

import java.util.ArrayList;
import java.util.List;

import com.seeyon.v3x.services.flow.bean.FlowExport;

import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.operate.IFormOperator;
import fy.mdm.bean.MaterialCodeChangeBean;
import fy.mdm.dao.MaterialCodeChangeDao;


public class MaterialCodeChangeFormOperator extends AForm_Save_Operator
		implements IFormOperator {

	private MaterialCodeChangeBean bean = new MaterialCodeChangeBean();
	private List<String> oldcodeList = new ArrayList<String>();
	private List<String> newMaterielCode = new ArrayList<String>();// 物料新编码
	private List<String> newMaterielDescribe = new ArrayList<String>();// 物料新描述
	private List<String> newMaterielDescribeEn = new ArrayList<String>();// 物料新描述英文
	private List<String> changeType = new ArrayList<String>();// 类型
	private List<String> changeReasion = new ArrayList<String>();// 变更原因
	private List<String> remark = new ArrayList<String>();// 备注
	private List<String> oldMeasurement = new ArrayList<String>();// 物料旧单位
	private List<String> newMeasurement = new ArrayList<String>();// 物料新单位
	private List<String> newModel = new ArrayList<String>();// 新型号
	private List<String> newBrand = new ArrayList<String>();// 新品牌
	private List<String> oldmain = new ArrayList<String>();// 旧属性
	private List<String> newmain = new ArrayList<String>();// 新属性

	@Override
	protected void parseOtherField_FirstStep(FlowExport flowExport) {
		bean.setSummaryId(super.formBean.getSummaryId());
		bean.setBillname(flowExport.getFlowTitle());
		bean.setApplier(flowExport.getFlowCreatePerson().getName());
		bean.setTs(flowExport.getFlowCreateTime());
	}

	@Override
	protected void parseValueExport(
			com.seeyon.v3x.services.form.bean.ValueExport ve) {
		String fieldName = ve.getDisplayName();
		if ("原编码".equals(fieldName)) {
			this.oldcodeList.add(ve.getValue());
		} else if ("需改成的编码".equals(fieldName)) {
			this.newMaterielCode.add(ve.getValue());
		} else if ("需改成的说明".equals(fieldName)) {
			this.newMaterielDescribe.add(ve.getValue());
		} else if ("需修改的型号".equals(fieldName)) {
			this.newModel.add(ve.getValue());
		} else if ("需修改的品牌".equals(fieldName)) {
			this.newBrand.add(ve.getValue());
		} else if ("需修改成的单位".equals(fieldName)) {
			this.newMeasurement.add(ve.getValue());
		} else if ("备注原因".equals(fieldName)) {
			this.remark.add(ve.getValue());
		} else if ("英文需修改成的说明".equals(fieldName)) {
			this.newMaterielDescribeEn.add(ve.getValue());
		} else if ("变更状态".equals(fieldName)) {
			this.changeType.add(ve.getValue());
		} 
		else if ("变更原因".equals(fieldName)) {
			this.changeReasion.add(ve.getValue());
		} 
		else if ("原单位".equals(fieldName)) {
			this.oldMeasurement.add(ve.getValue());
		}else if ("旧主属性".equals(fieldName)) {
			this.oldmain.add(ve.getValue());
		}else if ("新主属性".equals(fieldName)) {
			this.newmain.add(ve.getValue());
		}
	}

	public String getFormName() {
		return "集团物料编码变更申请表";
	}

	public boolean save() {
		bean.setOldcodeList(this.oldcodeList);
		bean.setNewMaterielCode(this.newMaterielCode);
		bean.setNewMaterielDescribe(this.newMaterielDescribe);
		bean.setNewMaterielDescribeEn(this.newMaterielDescribeEn);
		bean.setRemark(this.remark);
		bean.setChangeReasion(this.changeReasion);
		bean.setChangeType(this.changeType);
		bean.setOldMeasurement(this.oldMeasurement);
		bean.setNewMeasurement(this.newMeasurement);
		bean.setNewBrand(this.newBrand);
		bean.setNewModel(this.newModel);
		bean.setOldmain(this.oldmain);
		bean.setNewmain(this.newmain);
		
		MaterialCodeChangeDao materialCodeChangeDao = new MaterialCodeChangeDao();
		materialCodeChangeDao.setMaterialCodeChangeBean(bean);

		try {
			return materialCodeChangeDao.materialCodeChange();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {

			// bean.clear();
			bean = null;
		}

		return success;
	}

}
